home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
I-Z
/
Xlisp_Source.cpt
/
macstuff14.c
< prev
next >
Wrap
Text File
|
1985-04-08
|
7KB
|
356 lines
/* macstuff.c - macintosh interface routines for xlisp */
overlay "macstuff"
#include <qd.h>
#include <mem.h>
#include <file.h>
#include <font.h>
#include <win.h>
#include <menu.h>
#include <dialog.h>
#include <event.h>
#include <pack.h>
#include <stdio.h>
#define lastmenu 3
#define applemenu 1
#define filemenu 256
#define controlmenu 257
extern char *s_unbound;
#include <qdvars.h> /* quickdraw globals */
menuhandle mymenus[lastmenu];
rect screenrect,dragrect;
eventrecord myevent;
windowrecord wrecord;
windowptr mywindow,whichwindow;
rgnhandle updatergn;
sfreply loadfile;
ostype filetypes[] = { {'T','E','X','T'} };
int themenu,theitem;
int code,refnum;
int x,y;
#define TIMEON 500
#define TIMEOFF 100
int cursortime,cursorstate;
#define SCRH 24
#define SCRW 80
char screen[SCRH*SCRW],*topline,*curline;
#define LINEMAX 200
char linebuf[LINEMAX+1],*lineptr;
int linepos[LINEMAX],linelen;
#define CHARMAX 100
char charbuf[CHARMAX],*inptr,*outptr;
int charcnt;
macinit(name)
char *name;
{
initgraf(&theport);
initfonts();
initwindows();
initmenus();
teinit();
initdialogs(0L);
initcursor();
setupmenus();
setrect(&screenrect,5,40,505,335);
setrect(&dragrect,4,24,screenrect.a.right-4,screenrect.a.bottom-4);
mywindow = newwindow(&wrecord,&screenrect,name,1,0,-1L,1,0L);
setport(mywindow);
updatergn = newrgn();
textfont(monaco); textsize(9); textmode(srccopy);
cursorstate = -1;
curline = screen;
for (y = 0; y < SCRH; y++)
for (x = 0; x < SCRW; x++)
*curline++ = ' ';
topline = curline = screen;
inptr = outptr = charbuf;
linelen = charcnt = 0;
x = y = 0;
}
int macgetc(fp)
FILE *fp;
{
if (fp == stdin) return (linegetc());
else return (getc(fp));
}
int macputc(ch,fp)
int ch; FILE *fp;
{
macidle();
if (fp == stdout) return (lineputc(ch));
else return (putc(ch,fp));
}
setupmenus()
{
char appletitle[2];
int i;
appletitle[0] = applesymbol; appletitle[1] = 0;
mymenus[0] = newmenu(applemenu, appletitle);
addresmenu(mymenus[0],"DRVR");
mymenus[1] = newmenu(filemenu,"File");
appendmenu(mymenus[1],"Load.../L;(-;Quit/Q");
mymenus[2] = newmenu(controlmenu,"Control");
appendmenu(mymenus[2],"Break/B");
for (i = 0; i < lastmenu; i++)
insertmenu(mymenus[i],0);
drawmenubar();
}
int linegetc()
{
int ch;
if (linelen--) return (*lineptr++);
linelen = 0;
while ((ch = scrgetc()) != '\r')
switch (ch) {
case '\010':
if (linelen > 0) {
linelen--;
while (x > linepos[linelen]) {
scrputc('\010'); scrputc(' '); scrputc('\010');
}
}
break;
default:
if (linelen < LINEMAX) { linebuf[linelen] = ch; linepos[linelen] = x; linelen++; }
scrputc(ch);
break;
}
lineputc('\n');
linebuf[linelen] = '\n';
lineptr = linebuf;
return (*lineptr++);
}
int lineputc(ch)
int ch;
{
if (ch == '\n') scrputc('\r');
scrputc(ch);
return (1);
}
int scrgetc()
{
int ch;
cursorstate = cursortime = 0;
while (charcnt == 0)
macidle();
if (cursorstate == 1) { scrposition(x,y); drawchar(' '); }
cursorstate = -1;
ch = *outptr++; charcnt--;
if (outptr >= &charbuf[CHARMAX])
outptr = charbuf;
return (ch);
}
macidle()
{
int ch;
systemtask();
scrcursorupdate();
while (getnextevent(everyevent,&myevent))
switch (myevent.what) {
case mousedown:
code = findwindow(&myevent.where,&whichwindow);
switch (code) {
case inmenubar:
docommand(menuselect(&myevent.where));
break;
case insyswindow:
systemclick(&myevent,whichwindow);
break;
case indrag:
dragwindow(whichwindow,&myevent.where,&dragrect);
break;
case ingoaway:
if (trackgoaway(whichwindow,&myevent.where))
exit();
break;
case ingrow:
case incontent:
if (whichwindow != frontwindow())
selectwindow(whichwindow);
break;
}
break;
case keydown:
case autokey:
if (mywindow == frontwindow()) {
ch = myevent.message & 0xFF;
if (myevent.modifiers & 0x100)
switch (ch) {
case 'l':
case 'L':
docommand(filemenu,1); continue;
case 'q':
case 'Q':
docommand(filemenu,3); continue;
case 'b':
case 'B':
docommand(controlmenu,1); continue;
default:
ch &= 0x1F; break;
}
if (charcnt < CHARMAX) {
*inptr++ = ch; charcnt++;
if (inptr >= &charbuf[CHARMAX])
inptr = charbuf;
}
}
break;
case activateevt:
if (myevent.modifiers & 1)
;
else
;
break;
case updateevt:
setport(mywindow);
beginupdate(mywindow);
doupdate();
endupdate(mywindow);
break;
}
}
scrcursorupdate()
{
if (cursorstate != -1)
if (cursortime-- < 0) {
scrposition(x,y);
if (cursorstate) {
drawchar(' ');
cursortime = TIMEOFF;
cursorstate = 0;
}
else {
drawchar('_');
cursortime = TIMEON;
cursorstate = 1;
}
}
}
scrputc(ch)
int ch;
{
if (ch == '\r') x = 0;
else if (ch == '\n') { nextline(&curline); if (y < 23) y++; else scrollup(); }
else if (ch == '\t') { scrputc(' '); while (x & 7) scrputc(' '); }
else if (ch == '\010') { if (x) x--; }
else if (ch >= 0x20 && ch < 0x7F) {
scrposition(x,y);
drawchar(ch);
curline[x] = ch;
if (x < 79) x++;
else { x = 0; nextline(&curline); if (y < 23) y++; else scrollup(); }
}
}
scrposition(x,y)
int x,y;
{
moveto((x * 6) + 5,(y * 12) + 10);
}
pascal filefilter(pblock)
paramblkptr pblock;
{
char *p; int len;
p = pblock->ionameptr; len = *p++ &0xFF;
while (len--) if (*p++ == '.' && len == 3 && *p++ == 'l' && *p++ == 's' && *p == 'p') return (0);
return (0x100);
}
docommand(themenu,theitem)
int themenu,theitem;
{
char name[256];
point p;
hilitemenu(themenu);
switch (themenu) {
case applemenu:
getitem(mymenus[0],theitem,name);
refnum = opendeskacc(name);
break;
case filemenu:
switch (theitem) {
case 1: /* load */
p.a.h = 100; p.a.v = 100;
sfgetfile(&p,"",filefilter,-1,filetypes,0L,&loadfile);
if (loadfile.good) {
hilitemenu(0);
setvol(0L,loadfile.vrefnum);
if (!xlload(loadfile.fname,0,0))
xlabort("load error");
}
break;
case 3: /* quit */
exit();
}
break;
case controlmenu:
hilitemenu(0);
switch (theitem) {
case 1: /* break */
lineptr = linebuf; linebuf[0] = '\n'; linelen = 1;
xlbreak("user break",s_unbound);
break;
}
break;
}
hilitemenu(0);
}
doupdate()
{
char *line; int y;
line = topline;
for (y = 0; y < SCRH; y++) {
scrposition(0,y);
drawtext(line,0,SCRW);
nextline(&line);
}
}
nextline(pline)
char **pline;
{
if ((*pline += SCRW) >= &screen[SCRH*SCRW]) *pline = screen;
}
scrollup()
{
rect rect; int x;
setrect(&rect,0,0,500,295);
scrollrect(&rect,0,-12,updatergn);
for (x = 0; x < SCRW; x++) topline[x] = ' ';
nextline(&topline);
}